<!--
 * @Author: your name
 * @Date: 2020-02-17 10:19:07
 * @LastEditTime: 2020-03-18 11:18:05
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \boot_vue\src\App.vue
 -->
<template>
  <transition name="el-fade-in-linear">
    <router-view />
  </transition>
</template>

<script>
import Cookies from 'js-cookie'
// import consoleManager from '@/utils/consoleManager'
import { messages } from '@/i18n'
export default {
  watch: {
    '$i18n.locale': 'i18nHandle'
  },
  created () {
    this.i18nHandle(this.$i18n.locale)
    let favicon = document.querySelector('link[rel="icon"]')
    favicon = document.createElement('link')
    favicon.rel = 'icon'
    this.$http.get('/tb/LogoSettingController/getLogo').then(({ data: res }) => {
      if (res.code !== 0) {
        favicon.href = require('@/assets/img/favicon1.png')
        document.getElementsByTagName('head')[0].appendChild(favicon)
        return
      }
      favicon.href = res.data.webTab
      document.getElementsByTagName('head')[0].appendChild(favicon)
    }).catch(() => {
      favicon.href = require('@/assets/img/favicon1.png')
      document.getElementsByTagName('head')[0].appendChild(favicon)
    })
  },
  methods: {
    i18nHandle (val, oldVal) {
      Cookies.set('language', val)
      document.querySelector('html').setAttribute('lang', val)
      document.title = messages[val].brand.lg
      // 非登录页面，切换语言刷新页面
      if (this.$route.name !== 'login' && oldVal) {
        window.location.reload()
      }
    }
  }
}
</script>
